package com.example.onlinemonitoring;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author zkw
 * @date 2021.7.05
 */
@Configuration
@EnableSwagger2
// http://localhost:8098/swagger-ui.html
public class Swagger2Config {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2) // 主要api配置机制初始化为swagger规范2.0
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.onlinemonitoring.controller"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(unifiedAuth());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("RIXIN RESTful API V1.0.0") // 标题
                .description("文档日期：2021/7/6") // 描述信息
                .termsOfServiceUrl("localhost:8098") // 服务网址
                .version("1.0.0") // 版本号
                .build();
    }

    private static List<ApiKey> unifiedAuth() {
        List<ApiKey> arrayList = new ArrayList<>();
        arrayList.add(new ApiKey("app-type", "app-type", "header"));
        arrayList.add(new ApiKey("Authorization", "Authorization", "header"));
        return arrayList;
    }
}